package com.stray.crawl;

import java.net.URL;
import java.util.Map;

public final class TaskContext {

	private URL url;
	private String planName;

	private String method;
	private String agent;
	private int timeout;

	private boolean useReferer;
	private boolean useCache;

	private String charset;
	private String express;
	private String action;

	private String[] fields;
	private String[] queries;

	private Map<String, String> configs;
	private Map<String, String> params;

	public int indexOfField(String field) {
		if (field != null) {
			for (int i = 0; i < fields.length; i++) {
				if (field.equals(fields[i])) {
					return i;
				}
			}
		}

		return -1;
	}

	public boolean isAgentExist() {
		return agent != null && agent.length() > 0;
	}

	public boolean isCharsetExist() {
		return charset != null && charset.length() > 0;
	}

	public boolean isTimeoutExist() {
		return timeout > 0;
	}

	public boolean isConfigNotEmpty(String configKey) {
		String value = configs.get(configKey);
		return value != null && value.length() > 0;
	}

	public String getConfig(String configKey) {
		return configs.get(configKey);
	}

	public boolean isParamNotEmpty(String paramKey) {
		String value = params.get(paramKey);
		return value != null && value.length() > 0;
	}

	public String getParam(String paramKey) {
		return params.get(paramKey);
	}

	// Getter & Setter
	public URL getUrl() {
		return url;
	}

	public void setUrl(URL url) {
		this.url = url;
	}

	public String getPlanName() {
		return planName;
	}

	public void setPlanName(String planName) {
		this.planName = planName;
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public String getAgent() {
		return agent;
	}

	public void setAgent(String agent) {
		this.agent = agent;
	}

	public int getTimeout() {
		return timeout;
	}

	public void setTimeout(int timeout) {
		this.timeout = timeout;
	}

	public boolean isUseReferer() {
		return useReferer;
	}

	public void setUseReferer(boolean useReferer) {
		this.useReferer = useReferer;
	}

	public boolean isUseCache() {
		return useCache;
	}

	public void setUseCache(boolean useCache) {
		this.useCache = useCache;
	}

	public String getCharset() {
		return charset;
	}

	public void setCharset(String charset) {
		this.charset = charset;
	}

	public String getExpress() {
		return express;
	}

	public void setExpress(String express) {
		this.express = express;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public String[] getFields() {
		return fields;
	}

	public void setFields(String[] fields) {
		this.fields = fields;
	}

	public String[] getQueries() {
		return queries;
	}

	public void setQueries(String[] queries) {
		this.queries = queries;
	}

	public Map<String, String> getConfigs() {
		return configs;
	}

	public void setConfigs(Map<String, String> configs) {
		this.configs = configs;
	}

	public Map<String, String> getParams() {
		return params;
	}

	public void setParams(Map<String, String> params) {
		this.params = params;
	}

}